package com.atlzk.renting.city.controller;

import com.atlzk.common.entity.city.CityEntity;
import com.atlzk.common.utils.PageUtils;
import com.atlzk.common.utils.R;
import com.atlzk.renting.city.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * @author liuzekun
 * @email 2803587841@gmail.com
 * @date 2021-07-16 18:56:57
 */
@RestController
@RequestMapping("city/city")
@CrossOrigin
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("city:city:list")
    public R list(@RequestParam Map <String, Object> params) {
        PageUtils page = cityService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("city:city:info")
    public R info(@PathVariable("id") Integer id) {
        CityEntity city = cityService.getById(id);

        return R.ok().put("city", city);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("city:city:save")
    public R save(@RequestBody CityEntity city) {
        cityService.save(city);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("city:city:update")
    public R update(@RequestBody CityEntity city) {
        cityService.updateById(city);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("city:city:delete")
    public R delete(@RequestBody Integer[] ids) {
        cityService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 省市县  三级联动
     */
    @RequestMapping("/findAddress/{pid}")
    public List <CityEntity> findAddress(@PathVariable("pid") Integer pid){
        return cityService.findAddress(pid);
    }
}
